import machine
from machine import Pin
from machine import SPI
import time
spi = SPI(1, baudrate=1000000, polarity=0, phase=0, sck=machine.Pin(14), mosi=machine.Pin(13), miso=machine.Pin(12))
cs=machine.Pin(26, machine.Pin.OUT)
cs.value(1)
time.sleep_ms(30)
dmode = bytes([0x09,0x00])
slimit = bytes([0x0b, 0x07])
sdown = bytes([0x0c, 0x01])
dtest = bytes([0x0f, 0x00])
data  = bytes([0x02, 0xff])

cs.value(0)
spi.write(dmode)
cs.value(1)
time.sleep_ms(10)

cs.value(0)
spi.write(slimit)
cs.value(1)
time.sleep_ms(10)

cs.value(0)
spi.write(sdown)
cs.value(1)
time.sleep_ms(10)

cs.value(0)
spi.write(dtest)
cs.value(1)
time.sleep_ms(10)

cs.value(0)
spi.write(dtest)
cs.value(1)
time.sleep_ms(10)

for i in range(8):
    
    if i == 3 or i == 4 :
        data = bytes([i+1, 0xff])
    else:
        data = bytes([i+1, 0x18])
    cs.value(0)
    spi.write(data)
    cs.value(1)